/*******************************************************************
 * author   :  Charlies-ls
 * Date     :  2021-09-26
 * Function :  common defs
 * Copyright (c) 2021. artestplay@outlook.com. All Rights Reserved.
 *******************************************************************/

#ifndef AX_COM_H__
#define AX_COM_H__
 
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdbool.h>

#ifndef NULL
#define NULL 0
#endif

#ifndef NO
#define NO 0
#endif

#ifndef YES
#define YES 1
#endif

#ifndef TRUE
#define TRUE  1
#endif

#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL   0
#endif

#define ALLOCS(s) malloc((s))
#define ALLOC2(a,b) malloc(sizeof(a)+sizeof(b))
#define ALLOC(TYPE) (TYPE*)malloc(sizeof(TYPE))
#define ALLOCN(TYPE,N) (TYPE*)malloc(sizeof(TYPE)*(N))
#define FREE(p) free(p)
#define ZERO(a) memset(&a,0,sizeof(a))
#define M2S(R) #R
# define M_PI		3.14159265358979323846	/* pi */
#ifdef __WIN32
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
#define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0)
#endif

#define ax_check_and_return_zero(v,str) \
		if( !(v) ) \
		{ \
            if(str) \
            ax_error("%s: %s\n",__FUNCTION__,str); \
			return 0; \
                }

#define ax_check_and_return_false(v,str) \
if( !(v) ) \
    { \
            if(str) \
            ax_error("%s: %s\n",__FUNCTION__,str); \
            return false; \
    }

#define ax_check_and_return(v,str) \
		if(!(v)) \
		{ \
            if(str) \
            ax_error("%s: %s\n",__FUNCTION__,str); \
			return ; \
		}		
 
#define ax_check_and_exit(v,str) \
		if(!(v)) \
		{ \
            if(str) \
            ax_error("%s: %s\n",__FUNCTION__,str); \
			exit(0); \
		}		


#endif
